const Keyv = require('keyv');
let filename=__dirname+"/key.sqlite"
const keyv = new Keyv('sqlite://'+filename);
keyv.on('error', err => console.log('Connection Error', err));
// async function test(){
//     await keyv.set('foo', 'expires in 1 second', 1000); // true
//     await keyv.set('foo', 'never expires'); // true
//     await keyv.get('foo'); // 'never expires'
//     // await keyv.delete('foo'); // true
//     // await keyv.clear(); // undefined
// }
// test();
// let filename=__dirname+"/key.sqlite"
async function selectPassword(service, account) {
    return await keyv.get(service+"/"+account); // 'never expires'
}
async function setPassword(service, account,password) {
    let r=await selectPassword(service,account)
    if(r){//find
        await updatePassword(service, account,password)
    }else{
        await createPassword(service, account,password)
    }
}
async function createPassword(service, account,password) {
    await keyv.set(service+"/"+account,password);
}
async function updatePassword(service, account,password) {
    await keyv.set(service+"/"+account,password);
}
async function deletePassword(service, account) {
    await keyv.delete(service+"/"+account);
}
async function createTable() {
}
async function selectAccount(service,callback) {
    console.log("selectAccount");
}
async function init() {
    console.log("init");
}
module.exports={init,selectAccount,selectPassword,deletePassword,createTable,setPassword}